﻿@page "/xlsio/excel-to-pdf"
@inject Microsoft.JSInterop.IJSRuntime JS
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment
@using System.IO;

@using Syncfusion.Blazor.Buttons
@*Hidden:Lines*@

@using BlazorDemos.Data.FileFormats.XlsIO

@*End:Hidden*@
@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample deomonstrates how to convert spreadsheets to PDF documents using XlsIO.</p>
</SampleDescription>
<ActionDescription>
<p>This sample illustrates the conversion of a MS Excel document to a PDF format.</p>
<p style='display: block'>Essential XlsIO allows to export the Excel document into PDF document. Use the Convert method of ExcelToPDFConverter class to convert the Excel to PDF and save the PDF document. This enables the user to easily convert the Excel document to PDF document.</p>
<p style='display: block'><b>Features:</b></p>
<ul>
<li>Supports conversion of a Excel document to PDF document</li>
</ul>
<p style='display: block'><b>Note:</b>Installation of Essential PDF is necessary to run this sample</p>
</ActionDescription>

<div class="control-section">
    <p style="font-weight:normal">Clicking the button below will result in a PDF document being converted from Excel document using Essential XlsIO and Essential PDF. Please note that you need to have a PDF viewer installed in order to view the generated PDF file.</p>

    <div class="radio-control">
        <h5 class="row">PDF Page Setup options</h5>
        <div class="e-radio-wrapper">
            <SfRadioButton Label="NoScaling" Name="NoScaling" Value=@("NoScaling") @bind-Checked="@option"></SfRadioButton>
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div class="e-radio-wrapper">
            <SfRadioButton Label="FitAllRowsOnOnePage" Name="FitAllRowsOnOnePage" Value=@("FitAllRowsOnOnePage") @bind-Checked="@option"></SfRadioButton>
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div class="e-radio-wrapper">
            <SfRadioButton Label="FitAllColumnsOnOnePage" Name="FitAllColumnsOnOnePage" Value=@("FitAllColumnsOnOnePage") @bind-Checked="@option"></SfRadioButton>
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div class="e-radio-wrapper">
            <SfRadioButton Label="FitSheetOnOnePage" Name="FitSheetOnOnePage" Value=@("FitSheetOnOnePage") @bind-Checked="@option"></SfRadioButton>
        </div>
    </div>
    <div class="button-section">
        <div id="button-control">
            <div class="row">
                <div>
                    <SfButton @onclick="ConvertToPDF">Convert To PDF</SfButton>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .radio-control {
        margin: 5% 0 2% 0;
    }

    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream excelStream;
    string option = "FitSheetOnOnePage";

    /// <summary>
    /// Create and download the simple Excel document
    /// </summary>
    public async Task ConvertToPDF()
    {
        ExcelToPDFService service = new ExcelToPDFService(hostingEnvironment);
        excelStream = service.ExceltoPDFXlsIO(option);
        await JS.SaveAs("ExcelToPDF.pdf", excelStream.ToArray());
    }
}